﻿namespace Net.Share
{
    /// <summary>
    /// 网络命令基类 - 可继承此类定义自己的网络命令 19.7.16 (系统命令使用0-100) 请从100开始自定义命令
    /// </summary>
    public class NetCmd
    {
        public readonly byte value;

        public NetCmd(byte value)
        {
            this.value = value;
        }

        public static explicit operator NetCmd(byte value)
        {
            return new NetCmd(value);
        }

        /// <summary>
        /// 面向实体类型调用远程函数
        /// 使用此命令即可在派生于<see cref="Net.Server.ClientPeerBase"/>类型定义<see cref="Rpc"/>函数进行调用
        /// </summary>
        public readonly static NetCmd EntityRpc = (NetCmd)EntityRpcHash;
        public const byte EntityRpcHash = 0;
        /// <summary>
        /// 公共Rpc调用指令(<see langword="服务器的公共资源"/>)
        /// 如果是客户端调用则在服务器执行 如果是服务器调用则在客户端执行.
        /// 在服务器端,如果出现多线程抢夺资源调用Client错误时，可使用SafeCall命令来执行
        /// </summary>
        public readonly static NetCmd CallRpc = (NetCmd)CallRpcHash;
        public const byte CallRpcHash = 1;
        /// <summary>
        /// 安全调用服务器函数(<see langword="针对Client独立调用"/>),当多线程并行时会有概率发生资源竞争，导致数据错乱！
        /// 如果在RPC函数内部调用client的时候是其他客户端的client对象。出现这种情况时建议使用此命令，
        /// 否则可以使用CallRpc命令，
        /// 使用此命令时,函数第一个参数必须是派生于<see cref="Net.Server.ClientPeerBase"/>类型的参数
        /// </summary>
        public readonly static NetCmd SafeCall = (NetCmd)SafeCallHash;
        public const byte SafeCallHash = 2;
        /// <summary>
        /// (自身转发)服务器只转发给发送方客户端
        /// </summary>
        public readonly static NetCmd Local = (NetCmd)LocalHash;
        public const byte LocalHash = 3;
        /// <summary>
        /// (场景转发)服务器负责转发给在同一房间或场景内的玩家
        /// </summary>
        public readonly static NetCmd Scene = (NetCmd)SceneHash;
        public const byte SceneHash = 4;

        /// <summary>
        /// (公告指令)服务器负责转发给所有在线的玩家
        /// </summary>
        public readonly static NetCmd Notice = (NetCmd)NoticeHash;
        public const byte NoticeHash = 6;

        /// <summary>
        /// 发送心跳包命令, 内部命令
        /// </summary>
        public readonly static NetCmd KeepAlive = (NetCmd)KeepAliveHash;
        public const byte KeepAliveHash = 8;
        /// <summary>
        /// 回调心跳包命令, 内部命令
        /// </summary>
        public readonly static NetCmd KeepAliveAck = (NetCmd)KeepAliveAckHash;
        public const byte KeepAliveAckHash = 9;
        /// <summary>
        /// 多线程远程过程调用函数 (RPC)
        /// </summary>
        public readonly static NetCmd ThreadRpc = (NetCmd)ThreadRpcHash;
        public const byte ThreadRpcHash = 10;
        /// <summary>
        /// 请求服务器移除此客户端
        /// </summary>
        public readonly static NetCmd QuitGame = (NetCmd)QuitGameHash;
        public const byte QuitGameHash = 11;
        /// <summary>
        /// 其他命令或用户自定义命令
        /// </summary>
        public readonly static NetCmd Other = (NetCmd)OtherHash;
        public const byte OtherHash = 12;
        /// <summary>
        /// 安全调用服务器函数(<see langword="针对Client独立调用"/>),当多线程并行时会有概率发生资源竞争，导致数据错乱！
        /// 如果在RPC函数内部调用client时是其他客户端的client对象。出现这种情况时建议使用此命令，
        /// 否则可以使用CallRpc命令，
        /// 使用此命令时,函数第一个参数必须是派生于<see cref="Net.Server.ClientPeerBase"/>类型的参数.
        /// 此指令是线程池执行
        /// </summary>
        public readonly static NetCmd SafeCallAsync = (NetCmd)SafeCallAsyncHash;
        public const byte SafeCallAsyncHash = 13;
        /// <summary>
        /// 同步MySqlBuild生成的类, 当属性被修改后同步给(客户端/服务器)
        /// </summary>
        public readonly static NetCmd SyncPropertyData = (NetCmd)SyncPropertyDataHash;
        public const byte SyncPropertyDataHash = 14;

        /// <summary>
        /// 标记客户端唯一标识, 内部命令
        /// </summary>
        public readonly static NetCmd Identify = (NetCmd)IdentifyHash;
        public const byte IdentifyHash = 18;
        /// <summary>
        /// 操作同步，服务器使用NetScene.AddOperation方法，客户端UdpClient.AddOperation方法。 内部指令
        /// </summary>
        public readonly static NetCmd OperationSync = (NetCmd)OperationSyncHash;
        public const byte OperationSyncHash = 19;
        /// <summary>
        /// 局域网寻找主机命令, 内部使用
        /// </summary>
        public readonly static NetCmd Broadcast = (NetCmd)BroadcastHash;
        public const byte BroadcastHash = 20;
        /// <summary>
        /// 连接指令 (内部)
        /// </summary>
        public readonly static NetCmd Connect = (NetCmd)ConnectHash;
        public const byte ConnectHash = 21;
        /// <summary>
        /// 断开网络连接, 内部指令
        /// </summary>
        public readonly static NetCmd Disconnect = (NetCmd)DisconnectHash;
        public const byte DisconnectHash = 22;

        /// <summary>
        /// ping测试网络延迟量
        /// </summary>
        public readonly static NetCmd Ping = (NetCmd)PingHash;
        public const byte PingHash = 24;
        /// <summary>
        /// ping回调 内部指令
        /// </summary>
        public readonly static NetCmd PingCallback = (NetCmd)PingCallbackHash;
        public const byte PingCallbackHash = 25;
        /// <summary>
        /// 网络物体的同步指令 （NetworkObject之间同步）
        /// </summary>
        public readonly static NetCmd SyncVarNetObj = (NetCmd)SyncVarNetObjHash;
        public const byte SyncVarNetObjHash = 27;

        /// <summary>
        /// 字段或属性同步指令 内部指令 (客户端与服务器的Player字段同步)
        /// </summary>
        public readonly static NetCmd SyncVarP2P = (NetCmd)SyncVarP2PHash;
        public const byte SyncVarP2PHash = 29;
        /// <summary>
        /// 上传数据(大数据)
        /// </summary>
        public readonly static NetCmd UploadData = (NetCmd)UploadHash;
        public const byte UploadHash = 30;
        /// <summary>
        /// 下载数据(大数据)
        /// </summary>
        public readonly static NetCmd Download = (NetCmd)DownloadHash;
        public const byte DownloadHash = 31;
        /// <summary>
        /// 单线程安全调用服务器函数,当多线程同时访问一个方法时, 感觉这个方法不安全时, 需要使用单线程处理时, 可使用此命令
        /// 否则可以使用SafeCall或CallRpc命令，
        /// 使用此命令时,函数第一个参数将会嵌入NetPlayer参数
        /// </summary>
        public readonly static NetCmd SingleCall = (NetCmd)SingleCallHash;
        public const byte SingleCallHash = 32;
        /// <summary>
        /// 既有响应的rpc请求
        /// </summary>
        public readonly static NetCmd Response = (NetCmd)ResponseHash;
        public const byte ResponseHash = 33;
        /// <summary>
        /// 网关转发
        /// </summary>
        public readonly static NetCmd GatewayRelay = (NetCmd)GatewayRelayHash;
        public const byte GatewayRelayHash = 34;
        /// <summary>
        /// 如果被排队，服务器会发此命令给客户端
        /// </summary>
        public readonly static NetCmd QueueUp = (NetCmd)QueueUpHash;
        public const byte QueueUpHash = 35;
        /// <summary>
        /// 如果排队解除，服务器会发此命令给客户端
        /// </summary>
        public readonly static NetCmd QueueCancellation = (NetCmd)QueueCancellationHash;
        public const byte QueueCancellationHash = 36;
        /// <summary>
        /// 服务器爆满状态
        /// </summary>
        public readonly static NetCmd ServerFull = (NetCmd)ServerFullHash;
        public const byte ServerFullHash = 37;
    }
}